#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<string.h>
// int main(int argc,char *argv[],char* env[])
// {
//     int i =0;
//     for(;env[i];i++)
//     {
//         printf("%s\n",env[i]);
//     }
//     return 0;
// }

int main(int argc,char *argv[])
{
    // for(int i =0;i<argc;i++)
    // {
    //      printf("argv%d:%s",i,argv[i]);
    // }
    // extern char** environ;
    // int i =0;
    // for(;environ[i];i++)
    // {
    //     printf("%s\n",environ[i]);
    // }
    //printf("%s\n",getenv("PATH"));
    // char * env = getenv("MYENV");
    // if(env)
    // {
    //     printf("%s\n",env);
    // }


    char* who= getenv("USER");
    if(strcmp(who,"root") !=0)
    {
        printf("%s,是一个非法用户\n",who);
        //return 1;
        printf("myself command\n");
        printf("myself command\n");
        printf("myself command\n");
        printf("myself command\n");
        printf("myself command\n");
    }
    if(argc!= 2)
    {
        printf("touch:missing file operand\n");
        //return 1;
    }
    FILE* fp = fopen(argv[1],"w");
    if(fp!= NULL)fclose(fp);
    if(argc!=4)
    {
        printf("use error\nusage:%s op[-add]sub[mul][div] d2\n",argv[0]);
        //return 1;
    }
    int x = atoi(argv[2]);
    int y = atoi(argv[3]);
    int result =0;
    if(strcmp(argv[1],"-add") ==0)
    {
        result = x+y;
        printf("%d+%d=%d\n",x,y,result);
    }
    else  if(strcmp(argv[1],"-sub") ==0)
    {
        result = x-y;
        printf("%d-%d=%d\n",x,y,result);
    }

    else if(strcmp(argv[1],"-mul") ==0)
    {
        result = x*y;
        printf("%d+%d=%d\n",x,y,result);
    }

    else if(strcmp(argv[1],"-div") ==0)
    {
        result = x/y;
        printf("%d+%d=%d\n",x,y,result);
    }else
    {
         printf("Use error, you should use right command line\nUsage: %s op[-add|sub|mul|div] d1 d2\n", argv[0]); 
    }

    int i=0;
    for(;i<argc;i++)
    {
        printf("%d %s\n",i,argv[i]);
    }
    

}